#include "image_change.h"

image_change::image_change()
{

}

QByteArray image_change::get_image_arry(QString fileName, image_message_t msg)
{
    DEBUG_INFO(QString("width:%1--hight:%2").arg(msg.width).arg(msg.hight));
    QImage pixmap(msg.width,msg.hight,QImage::Format_RGB888);//(filename);
    pixmap.load(fileName);
    QImage fitpixmap = pixmap.scaled(msg.width,msg.hight, Qt::IgnoreAspectRatio).convertToFormat(QImage::Format_RGB888);
    quint16 length = fitpixmap.bytesPerLine();
    QByteArray arry;
    for (int i =0;i < fitpixmap.height();i++)
    {
        uchar* p_row = fitpixmap.scanLine(i);
        arry.append((char*)p_row,length);
    }

    if(msg.align_type == 1)//水平取点
        return arry;

    QByteArray item_arry;
    for(int i = 0; i< msg.width;i++)
    {
        for(int j = 0;j < msg.hight;j++)
        {
            item_arry.append(arry.mid((j*msg.width+i)*3,3));
        }
    }

    DEBUG_INFO(QString("%1").arg(item_arry.length()));

    return item_arry;

}


